﻿using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Mrsoft.Controls
{
    public static class ImageDrawing
    {
        public static void MenuPicture(object sender, PaintEventArgs e)
        {
            Control control = (Control)sender;
            //确认中心
            int x = control.Width / 2;
            int y = control.Height / 2;
            //画出外部边框
            SolidBrush br = new SolidBrush(control.ForeColor);
            Pen p = new Pen(br, 3);
            //绘制方框类图标
            e.Graphics.DrawLine(p, x - 5, y - 5, x + 2, y - 5);
            p.Width = 1;
            e.Graphics.DrawRectangle(p, new Rectangle(x - 4, y - 4, 9, 9));
            e.Graphics.DrawLine(p, x - 2, y - 2, x + 3, y - 2);
            e.Graphics.DrawLine(p, x - 2, y, x + 3, y);
            e.Graphics.DrawLine(p, x - 2, y + 2, x + 3, y + 2);
            p.Dispose();
            br.Dispose();
        }
        public static void MinPicture(object sender, PaintEventArgs e) 
        {
            Control control = (Control)sender;
            //确定三分之二的位置
            int x = control.Width / 2;
            int y = control.Height / 2;
            //画出图标
            Pen p = new Pen( control.ForeColor);
            e.Graphics.DrawLine(p, x - 5, y + 2, x + 5, y + 2);
            e.Graphics.DrawLine(p, x - 5, y + 3, x + 5, y + 3);
            p.Dispose();//释放绘图的资源
        }
        public static void MaxPicture(object sender, PaintEventArgs e) 
        {
            Control control = (Control)sender;
            //确定按钮的中心位置
            int x = control.Width / 2;
            int y = control.Height / 2;
            Pen p = new Pen( control.ForeColor);
            e.Graphics.DrawRectangle(p, new Rectangle(x - 5, y - 3, 11, 7));
            e.Graphics.DrawLine(p, x - 5, y - 2, x + 5, y - 2);
            p.Dispose();
        }
        public static void ClothPicture(object sender, PaintEventArgs e) 
        {
            Control control = (Control)sender;
            //确定按钮的中心位置
            int x = control.Width / 2;
            int y = control.Height / 2 + 2;
            //画出图标
            Pen p = new Pen(control.ForeColor,7);
            //SolidBrush br = new SolidBrush(this.ForeColor);
            //画出一个正方形宽4，高度4
            e.Graphics.DrawLine(p, x, y - 4, x, y + 4);
            p.Width = 2;
            e.Graphics.DrawLine(p, x - 2, y - 6, x - 6, y - 2);
            e.Graphics.DrawLine(p, x + 2, y - 6, x + 6, y - 2);
            p.Dispose();//释放绘图的资源
        }
        public static void ClosePicture(object sender, PaintEventArgs e) 
        {
            Control control = (Control)sender;
            //中心为方框的中心位置
            int x = control.Width / 2;
            int y = control.Height / 2;
            //画出图标
            Pen p = new Pen( control.ForeColor);
            e.Graphics.DrawLine(p, x - 4, y - 4, x + 4, y + 4);
            e.Graphics.DrawLine(p, x - 4 + 1, y - 4, x + 4 + 1, y + 4);
            e.Graphics.DrawLine(p, x + 4, y - 4, x - 4, y + 4);
            e.Graphics.DrawLine(p, x + 4 + 1, y - 4, x - 4 + 1, y + 4);
            p.Dispose();//释放绘图的资源
        }
        /// <summary>
        /// 去锐角
        /// </summary>
        public static void BeSuittable(Control control)
        {
            List<Point> list = new List<Point>();
            int width = control.Width;
            int height = control.Height;
            //左上
            list.Add(new Point(0, 1));
            list.Add(new Point(1, 0));
            //右上
            list.Add(new Point(width - 1, 0));
            list.Add(new Point(width, 2));
            //右下
            list.Add(new Point(width, height - 2));
            list.Add(new Point(width - 2, height));
            //左下
            list.Add(new Point(2, height));
            list.Add(new Point(0, height -2));
            Point[] points = list.ToArray();
            GraphicsPath shape = new GraphicsPath();
            shape.AddPolygon(points);
            //将窗体的显示区域设为GraphicsPath的实例 
            control.Region = new System.Drawing.Region(shape);
            shape.Dispose();
        }
    }
}
